package sanrenxing.dayEnd.backRepertoryTotal.service.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sanrenxing.dayEnd.backRepertoryTotal.dao.TrusteeSetupDao;
import sanrenxing.dayEnd.backRepertoryTotal.domain.TrusteeSetup;
import sanrenxing.dayEnd.backRepertoryTotal.service.TrusteeSetupBiz;

import java.util.HashMap;
import java.util.List;

/**
 * 功能：托管人业务层实现类
 * 编写者：蒋玲苹
 * 日期：
 * 版本：1.0
 */
@Service
public class TrusteeSetupBizImpl implements TrusteeSetupBiz {
    @Autowired
    private TrusteeSetupDao trusteeSetupDao;
    /**
     * 添加数据
     *
     * @param trusteeSetup
     * @return 0:添加失败,1:添加成功
     */
    @Override
    public int add(TrusteeSetup trusteeSetup) {
        return trusteeSetupDao.add(trusteeSetup);
    }

    /**
     * 删除数据
     *
     * @param custoIds
     * @return
     */
    @Override
    public int delete(String custoIds) {
        //判断是否为批量删除
        if(custoIds.contains(",")){
            //对编号按“，”分割
            String[] strs=custoIds.split(",");
            //循环删除
            for(String str:strs){
                //调用方法删除
                trusteeSetupDao.delete(Integer.parseInt(str));
            }
            //返回1
            return 1;
        }
        return trusteeSetupDao.delete(Integer.parseInt(custoIds));
    }

    /**
     * 修改数据
     *
     * @param trusteeSetup
     * @return
     */
    @Override
    public int update(TrusteeSetup trusteeSetup) {
        return trusteeSetupDao.update(trusteeSetup);
    }

    /**
     * 查询所有数据
     *
     * @param trusteeSetup
     * @param row
     * @param page
     * @return
     */
    @Override
    public List<TrusteeSetup> queryAll(TrusteeSetup trusteeSetup, int row, int page) {
        HashMap<String,Object> map=new HashMap<>();
        map.put("trusteeSetup",trusteeSetup);
        map.put("start",page);
        map.put("end",(page+row));
        return trusteeSetupDao.queryAll(map);
    }

    /**
     * 统计记录数
     *
     * @param trusteeSetup@return 记录行数据
     */
    @Override
    public int count(TrusteeSetup trusteeSetup) {
        return trusteeSetupDao.count();
    }
}
